#include "FenetrePrincipale.hpp"

#include "AffichagePrincipal.hpp"

#include <QtGui/QVBoxLayout>
#include <QtGui/QHBoxLayout>

#include <QtGui/QLabel>
#include <QtGui/QLineEdit>

#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QAction>
#include <QtGui/QKeySequence>

using namespace std;

FenetrePrincipale::FenetrePrincipale( QWidget * parent )
  : QMainWindow( parent )
{
  creerUI();
}

FenetrePrincipale::~FenetrePrincipale()
{
  static_cast< AffichagePrincipal* >( Composants.value( "Widget" ) ) -> sauverReglages();
}

void FenetrePrincipale::creerUI()
{
  // 
  AffichagePrincipal * affTmp = new AffichagePrincipal( this );
  connect( affTmp, SIGNAL( majFinie() ), this, SLOT( update() ) );
  setCentralWidget( affTmp );

  Composants . insert( "Widget", affTmp );

  QMenu * menuFichier = menuBar() -> addMenu( tr( "&Fichier" ) );

  QAction * actionCharger = menuFichier -> addAction( tr( "&Charger" ) );
  QAction * actionSauver = menuFichier -> addAction( tr( "&Sauver" ) );
  menuFichier -> addSeparator();
  QAction * actionFermer = menuFichier -> addAction( tr( "&Quitter" ) );

  actionCharger -> setShortcut( QKeySequence( tr( "Ctrl+o" ) ) );
  connect( actionCharger, SIGNAL( triggered() ),
	   affTmp, SLOT( chargerReglages() ) );

  actionSauver -> setShortcut( QKeySequence( tr( "Ctrl+s" ) ) );
  connect( actionSauver, SIGNAL( triggered() ),
	   affTmp, SLOT( sauverReglages() ) );

  actionFermer -> setShortcut( QKeySequence( tr( "Ctrl+q" ) ) );
  connect( actionFermer, SIGNAL( triggered() ), this, SLOT( close() ) );

  Composants . insert( "MenuFichier", menuFichier );
}
